import store from '@/assets/scripts/store'
import { HOS_GENERAL, HOS_WX } from '@/store/mutation-types.js'

const depType = [
  { label: '管理科室', value: '0' },
  { label: '门诊科室', value: '1' },
  { label: '观察科室', value: '2' },
  { label: '住院科室', value: '3' },
  { label: '医技科室', value: '4' },
  { label: '药剂科室', value: '5' },
  { label: '行政科室', value: '6' },
  { label: '职能科室', value: '7' },
  { label: '其他科室', value: '8' },
  { label: '医院病区', value: '9' }
  // {label: '医疗科室', value: '10'}
]

const dictFieldRc = {
  // dict type 1
  RC036: 'RC036-省、自治区、直辖市',
  RC0GJ: '国家',
  RC004: 'RC004-入院时情况代码',
  RC005: 'RC005-出院情况代码', // 出院转归
  RC0ZD: '诊断', // 诊断类型
  // dict type 2
  RC032: 'RC032-医疗付费方式代码',
  RC003: 'RC003-职业代码',
  RC033: 'RC033-联系人关系代码',
  RC013: 'RC013-麻醉方式代码',
  RC029: 'RC029-手术级别代码',
  RC014: 'RC014-切口愈合等级代码',
  RC0BW: '感染部位',
  // 其他
  RCCATY: '省医保-科别代码',
  RC001: 'RC001-性别代码',
  RC023: 'RC023-科别代码',
  RC030: 'RC030-ABO血型代码',
  RC027: 'RC027-入院病情代码',
  RC018: 'RC018-输血反应代码',
  RC016: 'RC016-死亡患者尸检代码',
  RC031: 'RC031-Rh血型代码表',
  RC002: 'RC002-婚姻状况代码',
  RC038: 'RC038-患者证件类别代码',
  RC019: 'RC019-离院方式代码',
  RC028: 'RC028-出院31天内再住院计划代码',
  RC024: 'RC024-麻醉分级代码',
  RC015: 'RC015-重症监护室名称代码',
  RC011: 'RC011-病案质量代码',
  RC026: 'RC026-入院途径代码',
  RC037: 'RC037-有无药物过敏', // 有 无
  RC007: 'RC007-血液学检查结果代码',
  RC039: 'RC039-判断代码', // 是 否
  RC035: 'RC035-民族',
  // 缺少
  RC0LJ: '临床路径管理', // 1完成 2变异 3退出 4未入
  RC600: '诊断符合情况' // 0未做、1符合、2不符合、3不确定
  // RC039: 'RC039-治疗类别',
  // RC040: 'RC040-实施临床路径'
}
const departRecord = '病案室'
const departNurse = '护士站'
const medicalInsurance = '医保办'
// const departServer = '服务台'
// const departAdmin = '科室管理员'

const COLUMNS = {
  matchRate: [
    { prop: 'time', label: '月份', width: 100, className: 'is-bold' },
    { prop: 'drg_mp_num', label: '结算病例数', width: 100 },
    { prop: 'mp_num', label: '病案病例数', width: 100 },
    { prop: 'match_num', label: '匹配病例数', width: 100 },
    { prop: 'match_rate', label: '匹配率', width: 100 }
  ],
  // 按病例数占比从高到低排序
  mdcAdrgDrgCount: [
    { prop: 'mdc_code', label: 'MDC编码', width: 100, className: 'is-bold' },
    { prop: 'mdc_name', label: 'MDC名称', width: 250, align: 'left' },
    { prop: 'adrg_num', label: 'ADRG组数', width: 100 },
    { prop: 'drg_num', label: 'DRG组数', width: 100 },
    { prop: 'num', label: '病例数', width: 100 },
    { prop: 'percent', label: '病例数占比%', width: 120 }
  ],
  // 按总病例数从高到低排序
  rwDistribution: [
    { prop: 'dept', label: '科室', width: 150, align: 'left', className: 'is-bold' },
    { prop: 'weights_avg', label: '平均权重', width: 90 },
    { prop: 'num', label: '总病例数', width: 90 },
    { prop: 'easy', label: '简单[0,1)', width: 100 },
    { prop: 'normal', label: '一般[1,3)', width: 100 },
    { prop: 'hard', label: '困难[3,+∞)', width: 100 },
    { prop: 'easy_percent', label: '简单%', width: 80 },
    { prop: 'normal_percent', label: '一般%', width: 80 },
    { prop: 'hard_percent', label: '困难%', width: 80 }
  ],
  // 按每CMI床日费用从低到高排序
  deptCmi: [
    { prop: 'dept', label: '科室', width: 150, align: 'left', className: 'is-bold' },
    { prop: 'cost', label: '住院费用总和', width: 120 },
    { prop: 'in_hos_day', label: '住院床日数', width: 100 },
    { prop: 'weights_sum', label: '权重数', width: 100 },
    { prop: 'num', label: '患者数', width: 90 },
    { prop: 'bed_day_fee', label: '每床日费用', width: 100 },
    { prop: 'cmi', label: 'CMI', width: 70 },
    { prop: 'bed_day_per_cmi', label: '每CMI床日费用', width: 130 }
  ],
  // 按每权重费用消耗指数从低到高排序
  costConsumptionIndexDept: [
    { prop: 'dept', label: '科室', width: 300, align: 'left', className: 'is-bold' },
    { prop: 'index', label: '费用消耗指数', width: 200 },
    { prop: 'num', label: '总病例数', width: 100 }
  ],
  // 按每权重时间消耗指数从低到高排序
  timeConsumptionzIndexDept: [
    { prop: 'dept', label: '科室', width: 300, align: 'left', className: 'is-bold' },
    { prop: 'index', label: '时间消耗指数', width: 200 },
    { prop: 'num', label: '总病例数', width: 100 }
  ],
  // 按每CMI床日费用从低到高排序-病组
  bedDayPerCmiDrg: [
    { prop: 'drg', label: '病组', width: 80, className: 'is-bold' },
    { prop: 'drg_name', label: '病组名称', width: 150, align: 'left' },
    { prop: 'in_hos_day', label: '住院床日数', width: 120 },
    { prop: 'weights_sum', label: '权重数', width: 100 },
    { prop: 'num', label: '患者数', width: 90 },
    { prop: 'bed_day_fee', label: '每床日费用', width: 100 },
    { prop: 'cmi', label: 'CMI', width: 70 },
    { prop: 'bed_day_per_cmi', label: '每CMI床日费用', width: 130 }
  ],
  // 按每权重费用消耗指数从低到高排序
  costConsumptionIndexDrg: [
    { prop: 'drg', label: '病组', width: 100, className: 'is-bold' },
    { prop: 'drg_name', label: '病组名称', width: 180, align: 'left' },
    { prop: 'index', label: '费用消耗指数', width: 150 },
    { prop: 'num', label: '总病例数', width: 100 }
  ],
  // 按每权重时间消耗指数从低到高排序
  timeConsumptionIndexDrg: [
    { prop: 'drg', label: '病组', width: 100, className: 'is-bold' },
    { prop: 'drg_name', label: '病组名称', width: 180, align: 'left' },
    { prop: 'index', label: '时间消耗指数', width: 150 },
    { prop: 'num', label: '总病例数', width: 100 }
  ],
  // 按平均结余费用从高到低排序
  balanceAnalysisDept: [
    { prop: 'dept', label: '科室', width: 180, align: 'left', className: 'is-bold' },
    { prop: 'balance_avg', label: '平均结余费用', width: 120 },
    { prop: 'balance_sum', label: '总结余费用', width: 100 },
    { prop: 'coef', label: '变异系数', width: 100 },
    { prop: 'nega_num', label: '亏损病例数', width: 100 },
    { prop: 'num', label: '总病例数', width: 100 },
    { prop: 'nega_percent', label: '亏损病例在该科室中比例%', width: 120 }
  ],
  // 按高倍率比例从高到低排序
  settleTypeDept: [
    { prop: 'dept', label: '科室', width: 150, align: 'left', className: 'is-bold' },
    { prop: 'num', label: '总病例数', width: 100 },
    { prop: 'low', label: '低倍率病例数', width: 110 },
    { prop: 'normal', label: '正常病例数', width: 110 },
    { prop: 'high', label: '高倍率病例数', width: 110 },
    { prop: 'low_percent', label: '低倍率比例%', width: 90 },
    { prop: 'normal_percent', label: '正常比例%', width: 90 },
    { prop: 'high_percent', label: '高倍率比例%', width: 90 }
  ],
  // 按平均结余费用从低到高排序
  balanceAnalysisDrg10: [
    { prop: 'drg', label: '病组', width: 80, className: 'is-bold' },
    { prop: 'drg_name', label: '病组名称', width: 150, align: 'left' },
    { prop: 'balance_avg', label: '平均结余费用', width: 120 },
    { prop: 'balance_sum', label: '总结余费用', width: 120 },
    { prop: 'coef', label: '变异系数', width: 80 },
    { prop: 'nega_num', label: '亏损病例数', width: 100 },
    { prop: 'num', label: '总病例数', width: 100 },
    { prop: 'nega_percent', label: '亏损病例在该科室中比例%', width: 110 }
  ],
  // 科室控费目标 按下调幅度从高到低排序
  feeControlDept: [
    { prop: 'dept', label: '科室', width: 150, align: 'left', className: 'is-bold' },
    { prop: 'cost_avg', label: '平均费用', width: 100 },
    { prop: 'local_avg', label: '区域费用', width: 100 },
    { prop: 'cost_delta_1', label: '下调金额', width: 100 },
    { prop: 'cost_delta_percent_1', label: '下调幅度%', width: 100 },
    { prop: 'cost_delta_2', label: '费用差额', width: 100 },
    { prop: 'cost_delta_percent_2', label: '费用差额幅度%', width: 120 },
    { prop: 'num', label: '总病例数', width: 100 }
  ],
  driverAnalysisHospitalStart: [
    { prop: 'factor', label: '住院费用动因分析', width: 100 }
  ],
  driverAnalysisHospitalEnd: [
    { prop: 'delta', label: '费用增长', width: 100 },
    { prop: 'percent', label: '率增长分析', width: 100 }
  ]
}
const INDEX_LIST = [{
  name: '服务能力',
  para: 'capacity',
  icon: '\ue7fc',
  children: [
    // {name: 'ADRG组数', value: '', unit: '', para: 'adrg_num', width: 100, tPara: ''},
    { name: 'DRG组数', value: '', unit: '', para: 'drgGroupCount', width: 90, tPara: 'drgGroupCount' },
    // {name: '出院病人数', value: '', unit: '', para: 'num', width: 120, tPara: ''},
    { name: '总权重数', value: '', unit: '', para: 'weight', width: 90, tPara: 'weight' },
    { name: 'CMI', value: '', unit: '', para: 'cmi', width: 60, tPara: 'cmi' }
  ]
}, {
  name: '服务效率',
  para: 'efficiency',
  icon: '\ue7e4',
  children: [
    { name: '平均住院日', value: '', unit: '', para: 'timeConsume', width: 100, tPara: 'timeConsume' },
    { name: '平均住院费用', value: '', unit: '', para: 'feeConsume', width: 120, tPara: 'feeConsume' },
    { name: '时间消耗指数', value: '', unit: '', para: 'timeConsumeExponent', width: 140, tPara: 'timeConsumeExponent' },
    { name: '费用消耗指数', value: '', unit: '', para: 'feeConsumeExponent', width: 150, tPara: 'feeConsumeExponent' }
    // {name: '每CMI床日费用', value: '', unit: '￥', para: 'bed_day_per_cmi', width: 120, tPara: ''},
    // {name: '例均住院天数', value: '', unit: '天', para: 'in_hos_day_avg', width: 120, tPara: ''}
  ]
}, {
//   name: '费用',
//   para: 'cost',
//   icon: '\ue6e0',
//   children: [
//     {name: '总费用', value: '', unit: '￥', para: 'cost_fee_sum', width: 100, tPara: ''},
//     {name: '例均费用', value: '', unit: '￥', para: 'cost_fee_avg', width: 100, tPara: ''},
//     {name: '耗占比', value: '', unit: '%', para: 'material_fee_percent', width: 100, tPara: ''},
//     {name: '药占比', value: '', unit: '%', para: 'medicine_fee_percent', width: 100, tPara: ''}
//   ]
// }, {
  name: '服务质量',
  para: 'quality',
  icon: '\ue6ce',
  children: [
    // {name: '15日再入院人次', value: '', unit: '', para: 'return_count', width: 140, tPara: ''},
    { name: '低风险组死亡率', value: '', unit: '', para: 'lowRiskDeathRate', width: 120, tPara: 'lowRiskDeathRate' }
  ]
}]

// 使用方法调用再次获取store里面的值
function constFun () {
  return {
    // todo 把这部分数据存储到Excel
    mainDataField: Object.assign({}, store && store.state.storeRule, {
      mainOperationName: { label: '主要手术名称', keyCode: 'mainOperationName', isHideSort: false, isHideReplace: true, isHideCpx: true },
      mainOperationCode: { label: '主要手术编码', keyCode: 'mainOperationCode', isHideSort: false, isHideReplace: true, isHideCpx: true },
      mainOutHosDiagnosisName: { label: '主要诊断名称', keyCode: 'mainOutHosDiagnosisName', isHideSort: false, isHideReplace: true, isHideCpx: true },
      mainOutHosDiagnosisCode: { label: '主要诊断编码', keyCode: 'mainOutHosDiagnosisCode', isHideSort: false, isHideReplace: true, isHideCpx: true },
      outDiagnosisString: { label: '诊断概述', keyCode: 'outDiagnosisString', isHideSort: true, isHideReplace: true, isHideCpx: true },
      operationString: { label: '手术概述', keyCode: 'operationString', isHideSort: true, isHideReplace: true, isHideCpx: true },
      transDepRecordString: { label: '转科概述', keyCode: 'transDepRecordString', isHideSort: true, isHideReplace: true, isHideCpx: true }
    })
  }
}
const OPTIONS_MONTHS = [
  { label: '一月', value: '01' },
  { label: '二月', value: '02' },
  { label: '三月', value: '03' },
  { label: '四月', value: '04' },
  { label: '五月', value: '05' },
  { label: '六月', value: '06' },
  { label: '七月', value: '07' },
  { label: '八月', value: '08' },
  { label: '九月', value: '09' },
  { label: '十月', value: '10' },
  { label: '十一月', value: '11' },
  { label: '十二月', value: '12' }
]
// 分值类别
const POINT_TYPES = [
  { label: '正常得分', className: 'ud-success', value: 'normal' },
  { label: '有加分', className: 'ud-purple', value: 'added' },
  { label: '有扣分', className: 'ud-danger', value: 'deducted' }
]
// 目录/指标类别
const PUBLIC_TYPES = [
  { label: '年', value: 'year' },
  { label: '月', value: 'month' }
]
export default {
  OPTIONS_MONTHS,
  POINT_TYPES,
  PUBLIC_TYPES,
  constFun,
  // 分页
  pageSize: 25,
  // 操作类型
  ops: {
    ADD: { label: '新增', type: 'success', keyCode: 'ADD' },
    EDIT: { label: '编辑', type: 'warning', keyCode: 'EDIT' },
    BATCH_EDIT: { label: '批量替换', type: 'warning', keyCode: 'BATCH_EDIT' },
    LOCK: { label: '锁定', type: 'warning', keyCode: 'LOCK' },
    LOCK_CANCEL: { label: '解锁', type: 'success', keyCode: 'LOCK_CANCEL' },
    DELETE: { label: '作废', type: 'danger', keyCode: 'DELETE' },
    DELETE_CANCEL: { label: '取消作废', type: 'success', keyCode: 'DELETE_CANCEL' },
    COLLECT: { label: '收藏', type: 'primary', keyCode: 'COLLECT' },
    COLLECT_CANCEL: { label: '取消收藏', type: 'primary', keyCode: 'COLLECT_CANCEL' },
    EXAM_RUN: { label: '质检', type: 'primary', keyCode: 'EXAM_RUN' },
    EXAM_SURE: { label: '审核确认', type: 'danger', keyCode: 'EXAM_SURE' },
    EXAM_CANCEL: { label: '取消审核', type: 'warning', keyCode: 'EXAM_CANCEL' },
    NURSE_RECEIVE: { label: '护士站签收', type: 'primary', keyCode: 'NURSE_RECEIVE', icon: 'el-icon-check' },
    RECORD_CHANGE_RECEIVE_TIME: { label: '修改签收时间', type: 'success', keyCode: 'RECORD_CHANGE_RECEIVE_TIME', icon: 'el-icon-edit' },
    RECORD_RECEIVE: { label: '病案室签收', type: 'warning', keyCode: 'RECORD_RECEIVE', icon: 'el-icon-check' },
    RECORD_CANCEL_RECEIVE: { label: '病案室撤销签收', type: 'danger', keyCode: 'RECORD_CANCEL_RECEIVE', icon: 'el-icon-close' },
    NURSE_CANCEL_RECEIVE: { label: '护士站撤销签收', type: 'danger', keyCode: 'NURSE_CANCEL_RECEIVE', icon: 'el-icon-close' },
    PLACEON: { label: '归档', type: 'success', keyCode: 'PLACEON', icon: 'el-icon-check' },
    CANCEL_PLACEON: { label: '归档撤销', type: 'danger', keyCode: 'CANCEL_PLACEON', icon: 'el-icon-close' },
    RETURN_BORROW: { label: '归还', type: 'success', keyCode: 'RETURN_BORROW', icon: 'el-icon-check' },
    BORROW: { label: '借阅', type: 'primary', keyCode: 'BORROW', icon: 'el-icon-check' }
  },
  // 医院类型
  hosTypeCore: '综合医院',
  hosTypeTown: '乡(镇)卫生院',
  hosTypeCh: '中医医院',
  // 用户类型 病案室 还是 护士站 权限不同
  departRecord,
  departNurse,
  // departServer,
  departList: [
    { value: departRecord, label: '病案室' },
    { value: departNurse, label: '护士站' },
    { value: medicalInsurance, label: '医保办' } // 医保办人员权限：只能修改病案首页上的特殊病例字段(specialCases)
    // {value: departServer, label: '服务台'}
    // {value: departAdmin, label: '科室管理员'}
  ],
  monitorCategory: {
    1: '总费用过高',
    2: '药耗过高',
    3: '总费用过低',
    4: '住院天数过长',
    5: '无法入组'
  },
  payItemMonitorCategory: {
    'sex': '性别错误',
    'repeat_charge': '重复收费',
    'date_limit': '超频次收费',
    'number_limit': '单次数量超标',
    'age_limit': '年龄错误',
    'hour_limit': '超24小时',
    'union_charge': '联合收费'
  },
  codeErrorCategory: {
    1: '编码映射异常',
    2: '编码存在泛码',
    3: '编码无效',
    4: '需合并编码',
    5: '无法入组',
    6: '手术操作与主要诊断不一致'
  },
  powerList: [
    { value: 'hospital', label: '全院' },
    { value: 'depart', label: '科室' },
    { value: 'doctor', label: '医生' }
  ],
  // 字典类型
  dictFlag: {
    keyCode: 'type',
    typeRc: 'RC',
    typeBase: null
  },
  // 签收标识 1-已签收
  record_receive_flag: {
    keyCode: 'record_receive_flag',
    yes: 1,
    no: 0
  },
  // 签收标识 1-已签收
  nurse_receive_flag: {
    keyCode: 'nurse_receive_flag',
    yes: 1,
    no: 0
  },
  // 收藏标志 1-已收藏
  collectFlag: {
    keyCode: 'collectFlag',
    yes: true,
    no: null
  },
  // 作废标志 1-已作废
  deleteFlag: {
    keyCode: 'deleteFlag',
    yes: true,
    no: false
  },
  // 审核标志 未执行-待审核 1-待确认 2-已确认
  examFlag: {
    keyCode: 'examFlag',
    wait: 1,
    already: 2,
    default: null
  },
  // 病案是否被借阅
  borrowFlag: {
    keyCode: 'borrowFlag',
    yes: '1', // 已借出
    no: '0' // 未借出
  },
  // 归还状态（BorrowPage)
  borrowReturnFlag: {
    keyCode: 'borrowReturnFlag',
    no: '0', // 全部未还
    yes: '1', // 全部归还
    partialReturn: '2' // 部分归还
  },
  // 数据库表名
  tableName: {
    MainPage: 'MainPage',
    MainPageOps: 'MainPageOps'
  },
  // 版本类型
  versionType: {
    ICD9CM3: { label: 'ICD-9-CM-3编码', keyCode: 'ICD-9-CM-3' },
    ICD10: { label: 'ICD-10编码', keyCode: 'ICD-10' }
  },
  // 同步医院的数据和本地的区分
  dataType: {
    keyCode: 'dataType',
    hos: '1', // 医院同步的
    local: '2' // 手动新增的
  },
  //  诊断类型 todo
  outDiagnosisType: {
    main: '主要',
    secondary: '其他',
    cplcOperate: '术后并发症',
    cplcNarcosis: '麻醉并发症',
    cplcOther: '其他并发症',
    infected: '医院感染',
    mainCh: '主病',
    secondaryCh: '主证'
  },
  operationPrimaryType: {
    main: '主要',
    secondary: '其他'
  },
  // 科室分类
  depType: depType,
  // 值域字典
  dictFieldRc: dictFieldRc,
  // 病案-字段列表-type针对病案首页类型（搜索类型或表格类型请自行拼接）
  // array 数组类型
  // input 基础输入框
  // input-num 数字输入框
  // select-num 数字下拉框
  // select 基础下拉框
  // select-remote 远程搜索下拉框 用于数据量多的条件
  // date 单个日期
  // dateTime 单个时间
  // daterange 日期范围
  // datetimerange 时间范围
  // 「label-名称，用于显示 和 字典表的category」
  // 「keyCode-保存到数据库的值」
  // 「type-字段在编辑时的类型」
  // 「tType-字段在搜索时的类型」
  // 「tWidth-表格展示时宽度、有该属性的值显示时超出需要省略」
  // 「cate-字典表的category」
  // 「regExpress-正则表达式」
  // todo 把这部分数据存储到Excel
  mainDataField: Object.assign({}, store && store.state.storeRule, {
    mainOperationName: { label: '主要手术名称', keyCode: 'mainOperationName', isHideSort: false, isHideReplace: true, isHideCpx: true },
    mainOperationCode: { label: '主要手术编码', keyCode: 'mainOperationCode', isHideSort: false, isHideReplace: true, isHideCpx: true },
    mainOutHosDiagnosisName: { label: '主要诊断名称', keyCode: 'mainOutHosDiagnosisName', isHideSort: false, isHideReplace: true, isHideCpx: true },
    mainOutHosDiagnosisCode: { label: '主要诊断编码', keyCode: 'mainOutHosDiagnosisCode', isHideSort: false, isHideReplace: true, isHideCpx: true },
    outDiagnosisString: { label: '诊断概述', keyCode: 'outDiagnosisString', isHideSort: true, isHideReplace: true, isHideCpx: true },
    operationString: { label: '手术概述', keyCode: 'operationString', isHideSort: true, isHideReplace: true, isHideCpx: true },
    transDepRecordString: { label: '转科概述', keyCode: 'transDepRecordString', isHideSort: true, isHideReplace: true, isHideCpx: true }
  }),
  // 结算数据对比表
  COLUMNS,
  // 绩效指标列表
  INDEX_LIST,
  // api map
  API_MAP: new Map([
    // 湖一总院
    [HOS_GENERAL, window.apiUrl.screen && window.apiUrl.screen.generalHos || window.apiUrl.sys],
    // 吴兴院区
    [HOS_WX, window.apiUrl.screen && window.apiUrl.screen.wxHos || window.apiUrl.sys]
  ]),
  // 违规等级
  WARN_LEVEL: [
    { keyCode: '', label: '全部' },
    { keyCode: '1', label: '1级明确违规' },
    { keyCode: '2', label: '2级高度可疑' },
    { keyCode: '3', label: '3级轻度可疑' }
  ]
}
